<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>健康饮食推荐</title>
    <meta name="keywords" content="面向学习型的开源框架，简洁高效，杜绝过渡封装，展现技术本质本质">
    <meta name="description" content="面向学习型的开源框架，简洁高效，杜绝过渡封装，展现技术本质本质">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm" >

                        <input id="id" name="id" th:value="${user.id}" class="form-control" type="hidden">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">登录名:</label>
                            <div class="col-sm-8">
                                <input id="username" name="username" th:value="${user.username}" readonly class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请输入新密码:</label>
                            <div class="col-sm-8">
                                <input id="password" name="password" onblur="checkPassword(this);" class="form-control" type="password">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">再次输入密码:</label>
                            <div class="col-sm-8">
                                <input id="password2" name="password2" onblur="checkPassword(this);" class="form-control" type="password">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <a id="modify" class="btn btn-primary">修改</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="/js/jquery.min.js?=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<script src="/js/bootstrap.min.js?v=3.3.6" th:src="@{/js/bootstrap.min.js?v=3.3.6}"></script>

<!-- 自定义js -->
<script src="/js/content.js?v=1.0.0" th:src="@{/js/content.js?v=1.0.0}"></script>

<!-- jQuery Validation plugin javascript-->
<script src="/js/ajax-util.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js" th:src="@{/js/plugins/validate/jquery.validate.min.js}"></script>
<script src="/js/plugins/validate/messages_zh.min.js" th:src="@{/js/plugins/validate/messages_zh.min.js}"></script>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>

<script type="text/javascript">

$(document).ready(function () {
	 $("#modify").on('click', function () {
		 var password1 = $("#password").val().trim();
		 var password2 = $("#password2").val().trim();
		 if(password1==null || password1=='' || password2==null || password2==''){
			 layer.msg("请输入新的密码");
			 return;
		 }
		 
		 if(password1 != password2){
			 layer.msg("两次密码输入不一致");
			 return; 
		 }
		 
		 //提交至后台
		 $.ajax({
	        type: "POST",
	        url: "/user/editPassword",
	        data: $('#signupForm').serialize(),
	        success: function (r) {
	            if (r.code == 0) {
	            	layer.msg("密码修改成功");
	            } else {
					layer.msg(r.msg);
	            }
	        }
	    });
		 
	 });
});

function checkPassword(obj){
	var password = $(obj).val().trim();
	if(password==null || password==''){
		layer.msg("请输入正确格式的密码");
		return;
	}
}

</script>
</body>
</html>
